//
//  UIView+IBInsepectable.swift
//  BPWeiBo
//
//  Created by 扒皮大叔 on 16/4/7.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

//@IBInsepectable   可以为视图在xib或者storyboard中添加可视化属性
//@IBDesignable  如果在一个 '自定义' 视图中添加@IBDesignable修饰, 那么@IBInsepectable 修饰的属性可以实时的显示

extension UIView {
    
    //MARK:设置view视图的圆角
    @IBInspectable var cornerRadius: CGFloat {
        
        //get
        get {
        //返回layer.Cornerradius
            return layer.cornerRadius
        }
        //set
        set {
            //设置 layer,connerRadius
            layer.cornerRadius = newValue
            //设置 maskToBounds
            if newValue > 0 {
                layer.masksToBounds = true
            }else {
                layer.masksToBounds = false
            }
        }
    }
    
    //MARk:设置描边,borderWidth
    @IBInspectable var borderWidth: CGFloat {
        //get
        get {
            //返回layer.borderWidth
            return layer.borderWidth
        }
        //set
        set {
            layer.borderWidth = newValue
      
        }
    
    }
    
    //MARK:设置描边的颜色,borderColor
    @IBInspectable var borderColor: UIColor? {
        //get
        get {
            if let c = layer.borderColor {
            return UIColor(CGColor: c)
            }
            //返回layer.borderColor
            return nil
        }
        //set
        set {
            layer.borderColor = newValue?.CGColor
            
        }
        
    }
    


}
